package com.inmobi.re.container.mraidimpl;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewParent;
import android.widget.FrameLayout;
import android.widget.FrameLayout.LayoutParams;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
import com.inmobi.commons.internal.Log;
import com.inmobi.re.container.CustomView;
import com.inmobi.re.container.CustomView.SwitchIconType;
import com.inmobi.re.container.IMWebView;
import com.inmobi.re.container.IMWebView.IMWebViewListener;
import com.inmobi.re.container.IMWebView.ViewState;
import com.inmobi.re.container.WrapperFunctions;
import com.inmobi.re.controller.JSController.ResizeProperties;
import java.util.concurrent.atomic.AtomicBoolean;

public class MRAIDResizeController
{
  protected static final int PLACEHOLDER_ID = 437;
  protected static final int RELATIVELAYOUT_ID = 438;
  private IMWebView a;
  private ResizeDimensions b = null;
  public JSController.ResizeProperties resizeProperties;

  public MRAIDResizeController(IMWebView paramIMWebView, Activity paramActivity)
  {
    this.a = paramIMWebView;
  }

  private FrameLayout a(JSController.ResizeProperties paramResizeProperties)
  {
    FrameLayout localFrameLayout1 = (FrameLayout)((ViewGroup)this.a.getOriginalParent()).getRootView().findViewById(16908290);
    a();
    FrameLayout localFrameLayout2 = new FrameLayout(this.a.getContext());
    FrameLayout.LayoutParams localLayoutParams1 = new FrameLayout.LayoutParams(WrapperFunctions.getParamFillParent(), WrapperFunctions.getParamFillParent());
    localFrameLayout2.setId(435);
    FrameLayout.LayoutParams localLayoutParams2 = new FrameLayout.LayoutParams(paramResizeProperties.width, paramResizeProperties.height);
    RelativeLayout localRelativeLayout = new RelativeLayout(this.a.getContext());
    localRelativeLayout.setId(438);
    RelativeLayout.LayoutParams localLayoutParams = new RelativeLayout.LayoutParams(paramResizeProperties.width, paramResizeProperties.height);
    localRelativeLayout.addView(this.a, localLayoutParams);
    a(localRelativeLayout, paramResizeProperties.customClosePosition);
    localFrameLayout2.addView(localRelativeLayout, localLayoutParams2);
    a(localFrameLayout1, localFrameLayout2, this.a, paramResizeProperties);
    localFrameLayout1.addView(localFrameLayout2, localLayoutParams1);
    this.a.setFocusable(true);
    this.a.setFocusableInTouchMode(true);
    this.a.requestFocus();
    return localFrameLayout2;
  }

  private RelativeLayout.LayoutParams a(String paramString)
  {
    String str = b(paramString);
    RelativeLayout.LayoutParams localLayoutParams = new RelativeLayout.LayoutParams((int)(50.0F * this.a.getDensity()), (int)(50.0F * this.a.getDensity()));
    if ((str.equals("top-right")) || (str.equals("bottom-right")))
      localLayoutParams.addRule(11);
    if ((str.equals("bottom-right")) || (str.equals("bottom-left")) || (str.equals("bottom-center")))
    {
      localLayoutParams.addRule(12);
      localLayoutParams.addRule(4);
    }
    if ((str.equals("bottom-center")) || (str.equals("top-center")) || (str.equals("center")))
      localLayoutParams.addRule(13);
    if (str.equals("top-center"))
      localLayoutParams.addRule(10);
    return localLayoutParams;
  }

  private void a()
  {
    try
    {
      FrameLayout localFrameLayout = new FrameLayout(this.a.getContext());
      localFrameLayout.setId(437);
      ViewGroup.LayoutParams localLayoutParams = new ViewGroup.LayoutParams(this.a.getWidth(), this.a.getHeight());
      ((ViewGroup)this.a.getOriginalParent()).addView(localFrameLayout, this.a.getOriginalIndex(), localLayoutParams);
      ((ViewGroup)this.a.getParent()).removeView(this.a);
      return;
    }
    catch (Exception localException)
    {
      Log.debug("IMRE_3.7.0", "Exception in replaceByPlaceHolder ", localException);
    }
  }

  private void a(ViewGroup paramViewGroup, String paramString)
  {
    RelativeLayout.LayoutParams localLayoutParams = a(paramString);
    CustomView localCustomView = new CustomView(this.a.getContext(), this.a.getDensity(), CustomView.SwitchIconType.CLOSE_TRANSPARENT);
    paramViewGroup.addView(localCustomView, localLayoutParams);
    localCustomView.setOnClickListener(new b());
  }

  private void a(FrameLayout paramFrameLayout1, FrameLayout paramFrameLayout2, IMWebView paramIMWebView, JSController.ResizeProperties paramResizeProperties)
  {
    int[] arrayOfInt1 = new int[2];
    int[] arrayOfInt2 = new int[2];
    ((View)paramIMWebView.getOriginalParent()).getLocationOnScreen(arrayOfInt1);
    paramFrameLayout1.getLocationOnScreen(arrayOfInt2);
    arrayOfInt1[1] -= arrayOfInt2[1];
    arrayOfInt1[0] -= arrayOfInt2[0];
    arrayOfInt1[0] += paramResizeProperties.offsetX;
    arrayOfInt1[1] += paramResizeProperties.offsetY;
    if (!paramResizeProperties.allowOffscreen)
    {
      if (paramResizeProperties.width > paramFrameLayout1.getWidth() - arrayOfInt1[0])
        arrayOfInt1[0] = (paramFrameLayout1.getWidth() - paramResizeProperties.width);
      if (paramResizeProperties.height > paramFrameLayout1.getHeight() - arrayOfInt1[1])
        arrayOfInt1[1] = (paramFrameLayout1.getHeight() - paramResizeProperties.height);
      if (arrayOfInt1[0] < 0)
        arrayOfInt1[0] = 0;
      if (arrayOfInt1[1] < 0)
        arrayOfInt1[1] = 0;
    }
    this.b = new ResizeDimensions(arrayOfInt1[0], arrayOfInt1[1], paramResizeProperties.width, paramResizeProperties.height);
    FrameLayout.LayoutParams localLayoutParams = new FrameLayout.LayoutParams(paramResizeProperties.width, paramResizeProperties.height);
    localLayoutParams.leftMargin = arrayOfInt1[0];
    localLayoutParams.topMargin = arrayOfInt1[1];
    localLayoutParams.gravity = 3;
    ((View)paramIMWebView.getParent()).setLayoutParams(localLayoutParams);
  }

  private String b(String paramString)
  {
    if ((!paramString.equals("top-left")) && (!paramString.equals("top-right")) && (!paramString.equals("bottom-left")) && (!paramString.equals("bottom-right")) && (!paramString.equals("top-center")) && (!paramString.equals("bottom-center")) && (!paramString.equals("center")))
      paramString = "top-right";
    return paramString;
  }

  private void b()
  {
    ((ViewGroup)this.a.getParent().getParent().getParent()).removeView((View)this.a.getParent().getParent());
    ((ViewGroup)this.a.getParent()).removeView(this.a);
    View localView = ((View)this.a.getOriginalParent()).findViewById(437);
    ((ViewGroup)localView.getParent()).removeView(localView);
    ((ViewGroup)this.a.getOriginalParent()).addView(this.a, this.a.getOriginalIndex());
    this.a.resetLayout();
  }

  public void closeResized()
  {
    if (this.a.getViewState().compareTo(IMWebView.ViewState.DEFAULT) == 0)
      return;
    synchronized (this.a.mutex)
    {
      this.a.isMutexAquired.set(false);
      this.a.mutex.notifyAll();
      this.a.doNotFireVisibilityChanged.set(true);
      b();
      this.a.closeResized();
      this.a.setVisibility(0);
      this.a.setState(IMWebView.ViewState.DEFAULT);
      this.a.doNotFireVisibilityChanged.set(false);
      return;
    }
  }

  public void doResize(Bundle paramBundle)
  {
    this.a.doNotFireVisibilityChanged.set(true);
    try
    {
      if (this.a.getOriginalParent() == null)
        this.a.saveOriginalViewParent();
      if (((FrameLayout)this.a.getParent().getParent()).getId() == 435)
      {
        a((FrameLayout)this.a.getParent().getParent().getParent(), (FrameLayout)this.a.getParent().getParent(), this.a, this.resizeProperties);
        RelativeLayout.LayoutParams localLayoutParams1 = a(this.resizeProperties.customClosePosition);
        RelativeLayout.LayoutParams localLayoutParams2 = new RelativeLayout.LayoutParams(this.resizeProperties.width, this.resizeProperties.height);
        this.a.setLayoutParams(localLayoutParams2);
        ((ViewGroup)this.a.getParent()).getChildAt(1).setLayoutParams(localLayoutParams1);
        if (paramBundle != null)
          this.a.setState(IMWebView.ViewState.RESIZED);
        this.a.requestLayout();
        this.a.invalidate();
        this.a.post(new c());
        this.a.doNotFireVisibilityChanged.set(false);
        return;
      }
    }
    catch (Exception localException1)
    {
      try
      {
        a(this.resizeProperties).setBackgroundColor(0);
        this.a.mAudioVideoController.videoValidateWidth = this.resizeProperties.width;
        if (paramBundle != null)
          this.a.setState(IMWebView.ViewState.RESIZED);
        synchronized (this.a.mutex)
        {
          this.a.isMutexAquired.set(false);
          this.a.mutex.notifyAll();
          this.a.requestLayout();
          this.a.invalidate();
          this.a.post(new a());
          this.a.doNotFireVisibilityChanged.set(false);
          return;
        }
      }
      catch (Exception localException2)
      {
        while (true)
        {
          Log.debug("IMRE_3.7.0", "Exception in doresize ", localException2);
          this.a.setState(IMWebView.ViewState.DEFAULT);
          synchronized (this.a.mutex)
          {
            this.a.isMutexAquired.set(false);
            this.a.mutex.notifyAll();
          }
        }
      }
    }
  }

  public void onOrientationChange()
  {
    if ((this.a.getStateVariable() == IMWebView.ViewState.RESIZED) && (!this.resizeProperties.allowOffscreen))
      doResize(null);
  }

  public void reset()
  {
    this.resizeProperties = new JSController.ResizeProperties();
  }

  class a
    implements Runnable
  {
    a()
    {
    }

    public void run()
    {
      if (MRAIDResizeController.a(MRAIDResizeController.this).mListener != null)
        MRAIDResizeController.a(MRAIDResizeController.this).mListener.onResize(MRAIDResizeController.b(MRAIDResizeController.this));
    }
  }

  class b
    implements View.OnClickListener
  {
    b()
    {
    }

    public void onClick(View paramView)
    {
      IMWebView.userInitiatedClose = true;
      MRAIDResizeController.a(MRAIDResizeController.this).close();
    }
  }

  class c
    implements Runnable
  {
    c()
    {
    }

    public void run()
    {
      if (MRAIDResizeController.a(MRAIDResizeController.this).mListener != null)
        MRAIDResizeController.a(MRAIDResizeController.this).mListener.onResize(MRAIDResizeController.b(MRAIDResizeController.this));
    }
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.inmobi.re.container.mraidimpl.MRAIDResizeController
 * JD-Core Version:    0.6.2
 */